﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CompareForeignKeyStructure.cs" company="SmartPlan">
//   SmartPlan 2011
// </copyright>
// <summary>
//   The compare foreign key structure.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DbDiff.Common.Comparer
{
    using System;
    using System.Data;
    using DataAccess;
    using Helper;
    using Model;

    /// <summary>
    /// The compare foreign key structure.
    /// </summary>
    internal sealed class CompareForeignKeyStructure : CompareDataStructure
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="CompareForeignKeyStructure"/> class. 
        /// The compare foreign key structure.
        /// </summary>
        /// <param name="databaseCompare">
        /// Compare object
        /// </param>
        /// <param name="objectType">
        /// Object type
        /// </param>
        public CompareForeignKeyStructure(DatabaseCompare databaseCompare, DatabaseObjectTypes objectType) : base(databaseCompare, objectType)
        {
            this.dv1Name = databaseCompare.DatabaseInfoBaseLeft.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.ForeignKeyByTableName);
            this.dv1Key = databaseCompare.DatabaseInfoBaseLeft.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.ForeignKeyByKey);
            this.dv2Name = databaseCompare.DatabaseInfoBaseRight.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.ForeignKeyByTableName);
            this.dv2Key = databaseCompare.DatabaseInfoBaseRight.DatabaseDataSets.GetDataView(DatabaseDataSets.DtView.ForeignKeyByKey);

            this.rowColumnName = DataRowCompareIndex.ForeignKey;
        }

        /// <summary>
        /// The compare.
        /// </summary>
        /// <param name="foreignName">
        /// The foreign name.
        /// </param>
        /// <returns>
        /// The compared result message
        /// </returns>
        public string Compare(string foreignName)
        {
            this.indexName = foreignName;

            return base.Compare();
        }

        /// <summary>
        /// Compare function not implemented
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        /// <returns>
        /// The compare.
        /// </returns>
        public override string Compare()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Find Index keys
        /// </summary>
        /// <param name="dv">
        /// The dataview for sorting
        /// </param>
        /// <param name="sort">
        /// sort when true
        /// </param>
        /// <returns>
        /// The sorted datarowview
        /// </returns>
        protected override DataRowView[] FindRows(DataViewDs dv, bool sort)
        {
            object[] obj = new object[] { this.cmp.CurrentOwner, this.cmp.CurrentName, this.indexName };
            return dv.FindRows(obj, sort);
        }
    }
}